package org.hismig.test.migration;

import org.hismig.cfg.Configuration;
import org.hismig.migration.Constructor;
import org.hismig.migration.Context;
import org.hismig.migration.executor.TableExecutor;
import org.hismig.migration.result.DBResultInfo;
import org.hismig.migration.result.TableResultInfo;

import junit.framework.TestCase;

/**
 * @declare: //TODO <br />
 *           This class created by Vansion.Hopihit on 2012-07-04 <br />
 *           <a href="mailto:vansionhopihit@gmail.com">Contact Me</a>
 * @version 1.0
 * @author Vansion.Hopihit
 * 
 */
public class ExecutorTester extends TestCase {

	private Constructor constructor;

	@Override
	protected void setUp() throws Exception {
		Configuration configuration = new Configuration(ExecutorTester.class
				.getResource("HisMig.cfg.xml").toURI());
		constructor = new Constructor();
		constructor.init(configuration);
	}

	public void testTableExecutor() {

		Context context = constructor.initContext(null);

		for (TableExecutor tableExecutor : constructor.getDbExecutors().get(0)
				.getTableExecutors()) {
			TableResultInfo tableResultInfo = tableExecutor.execute(context);

			assertNotNull(tableResultInfo);
			assertEquals(0, tableResultInfo.getErrorCount());
		}

	}

	public void testDBExecutor() {
		Context context = constructor.initContext();

		DBResultInfo dbResultInfo = constructor.getDbExecutors().get(0)
				.execute(context);

		assertNotNull(dbResultInfo);
		assertEquals(0, dbResultInfo.getErrorCount());
	}
}
